﻿CREATE TABLE [CD].[CashRegisters] (
    [Id]            INT           NOT NULL,
    [DepartmentId]  AS            ([Id]/(100000000)),
    [Name]          VARCHAR (50)  NOT NULL,
    [KKMNumber]     VARCHAR (20)  NULL,
    [NextDocNumber] INT           CONSTRAINT [DF_CashRegisters_NextDocNumber] DEFAULT ((1)) NOT NULL,
    [Note]          VARCHAR (250) NULL,
    [MD]            DATETIME      CONSTRAINT [DF__CashRegister__MD__2759D01A] DEFAULT (getdate()) NOT NULL,
    [MW]            VARCHAR (50)  CONSTRAINT [DF__CashRegister__MW__284DF453] DEFAULT (suser_sname()) NOT NULL,
    CONSTRAINT [PK_CashRegisters] PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT [IX_CashRegisters_Name] UNIQUE NONCLUSTERED ([Name] ASC)
);


GO

CREATE TRIGGER CD.CashRegistersDeleteLog ON CD.CashRegisters AFTER DELETE
AS 
BEGIN
	SET NOCOUNT ON;

INSERT INTO [PR].[DocDeleteLog] (TableName, IdValue, MD, MW)
SELECT 'CD.CashRegisters', Id, getdate(), SYSTEM_USER FROM DELETED

END

GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Наименование кассы для печати чеков', @level0type = N'SCHEMA', @level0name = N'CD', @level1type = N'TABLE', @level1name = N'CashRegisters', @level2type = N'COLUMN', @level2name = N'Name';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Заводской номер ККМ', @level0type = N'SCHEMA', @level0name = N'CD', @level1type = N'TABLE', @level1name = N'CashRegisters', @level2type = N'COLUMN', @level2name = N'KKMNumber';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Номер следующего чека', @level0type = N'SCHEMA', @level0name = N'CD', @level1type = N'TABLE', @level1name = N'CashRegisters', @level2type = N'COLUMN', @level2name = N'NextDocNumber';

